<?php

namespace App\Http\Resources\nursery;

use App\Models\fund\Coupon;
use App\Models\goods\Goods;
use App\Models\goods\GoodsCollection;
use Illuminate\Http\Resources\Json\ResourceCollection;

class NurseryPageCollection extends ResourceCollection
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {

        return [
            'total' => $this->resource->total(),
            'perPage' => $this->resource->perPage(),
            'current_page' => $this->resource->currentPage(),
            'items' => $this->collection->map(function ($item) {
                return [
                    'id' => $item->id,
                    'user_id' => $item->user_id,
                    'real_name' => $item->real_name,
                    'header_img' => $item->header_img,
                    'job_age' => $item->job_age,
                    'distance' =>  getDistance( $item->distance),
                    'price' => $item->price,
                    'star' => $item->star,
                    'major_id' => $item->major_id,
                ];
            })
        ];

    }
}
